package com.example.myprojects.service;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;

import com.example.myprojects.MyNews;
import com.example.myprojects.uitl.HttpUtil;

import java.io.IOException;

public class MyService  extends Service {
    HttpUtil httpUtil;
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    public MyService() {
        super();
    }

    @Override
    public void onCreate() {
        super.onCreate();
    }

    @Override
    public int onStartCommand(final Intent intent, int flags, int startId) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        httpUtil=new HttpUtil();
                        MyNews myNews = httpUtil.connectServer();
                        Intent intent1=new Intent();
                        intent1.setAction("com.example.myprojects");
                        intent1.putExtra("mynews",myNews);
                        sendBroadcast(intent1);
                    }catch (IOException e){
                        e.printStackTrace();
                    }
                }
            }).start();
        return super.onStartCommand(intent, flags, startId);

    }
    @Override
    public void onDestroy() {
        super.onDestroy();
    }
}
